<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>

<script>
    (function () {
        //普通函数
        function func() {
            let x = 10;
            this.num = x + 20 //给window上面添加了一个num属性
            console.log(this.num, window.num)//30 30  this指向winodw
        }
        const a = func()
        const b = func()
        console.log(a === b)//true
    })()
</script>
<script>
       (function () {
           //自定义类
           function func2() {
               //let obj = {} 默认一个私有的有实例对象 
               let x = 10;
               this.num = x + 20  //this.num 相当于给obj上面添加了一个属性
               console.log(this.num, window.num)//30  undefined
           }
           let f = new func2() //f2.num 直接调用数据
           let f2 = new func2() //f与f2是没有关系，相互独立的，两个不同的堆内存
           console.log(f === f2) //false
       })()

</script>

<script>
        (function () {
            function fn3() { }
            let f3 = fn3()
            console.log(f3) //undefined
            function fn4() { }
            let f4 = new fn4()
            console.log(f4) //fn4 {}
        })()

</script>

</html>